//
//  LeTVViewController.m
//  Courses
//
//  Created by YiXuePxh on 15/5/5.
//  Copyright (c) 2015年 boyibang. All rights reserved.
//

#import "LeTVViewController.h"
#import "LTCMoviePlayerController.h"
#import "CoursesViewController.h"
#import "LeTVRecord.h"
#define TIMER 300.0
@interface LeTVViewController ()<LTCMoviePlayerControllerDelegate>
@property (nonatomic, strong) LTCMoviePlayerController *moviePlayerController;
@property(nonatomic,strong)NSTimer* myTimer;
@end

@implementation LeTVViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _moviePlayerController = [[LTCMoviePlayerController alloc] initWithUserId:_user_unique videoId:_video_unique movieSourceType:LTCMovieSourceTypeNormal];
    _moviePlayerController.delegate = self;
    //时间统计  每五分钟 给服务器一个反馈
    _myTimer = [NSTimer scheduledTimerWithTimeInterval:TIMER target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
}


- (void) viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
    CGSize screenSize = [UIScreen mainScreen].bounds.size;
    double version = [[[UIDevice currentDevice]systemVersion] doubleValue];
    if (version < 8.0) {
        _moviePlayerController.playerView.frame = CGRectMake(0, 0, screenSize.height, screenSize.width);
    }else{
        _moviePlayerController.playerView.frame = CGRectMake(0, 0, screenSize.width, screenSize.height);
    }
    
    _moviePlayerController.controlStyle = LTCMovieControlStyleFullscreen;
    [self.view addSubview:_moviePlayerController.playerView];
    
}

- (void)ltcPlayerViewTopControlBtnDidClicked:(LTCMoviePlayerController *)controller{
    [_moviePlayerController releasePlayer];
    _moviePlayerController = nil;
    //取消定时器操作
    [_myTimer invalidate];
    _myTimer = nil;
    [self dismissViewControllerAnimated:YES completion:nil];
}

//  实现以下方法可以实现Controller 的旋转

- (BOOL)shouldAutorotate
{
    return YES;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeRight;
}

-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}

//记时  反馈  系统
-(void)timerAction{
    NSLog(@"记时啦   。。。。。");
    if ([User isLoggedIn]) {
        [LeTVRecord recordDataByVideoSourse:@"2" UserId:[User currentUser].userId CourseType:@"2" CourseId:@"2" LesssonId:_video_unique VideoId:_video_unique YxName:[User currentUser].userName];
    }else{
        [LeTVRecord recordDataByVideoSourse:@"2" UserId:@"YK" CourseType:@"2" CourseId:@"2" LesssonId:_video_unique VideoId:_video_unique YxName:@"YXYK"];
    }
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
